<?php
/**
 * Created by PhpStorm.
 * User: liuguang
 * Date: 2018/11/7
 * Time: 16:20
 * desc:品牌
 */
namespace app\index\controller;

use think\Controller;
use app\index\model\Brand;
class Brands extends Comm
{
	//品牌首页
	 public function index()
    {
		$bra=new Brand();
		$rs=$bra->index();
		$this->assign('rs',$rs);
		return view('index');
    }
	//品牌添加
	 public function addBrands()
    {
        if(isset($_POST['sub']))
        {
            $bra=new Brand();
            $rs=$bra->addBrand();
            if($rs)
            {
                $this->success('操作成功','index/brands/index');
            }
            else
            {
                $this->error('操作失败','index/brands/index');
            }
        }
        zsgc('添加了品牌数据');
        return view('addbrands');
	}
	//品牌修改
		 public function modBrands()
    {
        $bra = new Brand;
        if(isset($_POST['sub']))
        {
            $rs = $bra->modBrand();
            if ($rs)
            {
                $this->success('操作成功', 'index/brands/index');
            }
            else
             {
                $this->error('操作失败', 'index/brands/index');
             }
        }
		else
		    {
			$rs=$bra->where('id',input('hid'))->find();
			$this->assign('rs',$rs);
                zsgc('修改了品牌数据');
            return view('modbrands');
		}
    }
	//品牌删除
		 public function delBrands()
    {
         $id = trim(input('id'));
        $data = Brand::get($id);
        $path=ROOT_PATH . 'public' . DS . 'static' . DS . 'upload'. DS .$data['logo'];
        if(file_exists($path)){
            @unlink($path);
            clearstatcache();
        }
        $data = Brand::destroy($id);
        zsgc('删除了品牌数据');
		if($data==false){
            show(0,'品牌删除失败');
        }else{
            show(1,'品牌删除成功');
        }
    }
}
